package mid;

import org.junit.Test;

public class a264_丑数II {
    public int nthUglyNumber(int n) {
        if(n==0){
            return 0;
        }
        int []arr=new int[n];
        arr[0]=1;
        int p2=0,p3=0,p5=0;
        for(int i=1;i<n;i++){
            arr[i]=Math.min(2*arr[p2],Math.min(arr[p3]*3,arr[p5]*5));
            if(arr[i]==2*arr[p2]) p2++;
            if(arr[i]==3*arr[p3]) p3++;
            if(arr[i]==5*arr[p5]) p5++;
        }
        return arr[n-1];
    }
    @Test
    public void  tets(){
        System.out.println(nthUglyNumber(10));
    }
}
